// pages/information/information.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    casArray: ['请选择', '信息产业', '建筑工程', '石油化工', '服装纺织', '轻工食品'],
    casArrayd: ['请选择','特大型企业', '大型企业', '中型企业', '小型企业','微型企业'],
    userName: '',
    mobile: '',
    nickName: "",
    avatarUrl: "",
    Gender: 'female',
    casIndexd: 0,
    casIndex: 0,
    enterprise_corporate_name: "",
    enterprise_logo: "/image/1.jpg",
    enterprise_credit_code:"",
    enterprise_unit_address:"",
    enterprise_mailbox:"",
    enterprise_company_profile:"",
    enterprise_company_industry:"",
  },
/**行业选择 */
  bindCasPickerChange: function (e) {
    console.log(this.data.casArray);
    console.log('下拉选择的是', this.data.casArray[e.detail.value])
    this.setData({
      casIndex: e.detail.value
    })
  },
  bindCasPickerChanged: function (e) {
      console.log(this.data.casArrayd);
      console.log('下拉选择的是', this.data.casArray[e.detail.value])
      this.setData({
        casIndexd: e.detail.value
      })
  },
  /**
   * 选择图片
   */
  chooseImage:function(e){
    var that = this;
    wx.chooseImage({
      count: 1,
      sizeType: ['compressed'],
      sourceType: ['album','camera'],
      success: function(res) {
        var tempFilePaths = res.tempFilePaths;
        //启动上传等待中...
        wx.showToast({
          title: '正在上传...',
          icon: 'loading',
          mask: true,
          duration: 10000
        })

        wx.uploadFile({
          url: 'http://www.recruit.com/api/enterprise/upload',
          filePath: tempFilePaths[0],
          name: 'file',
          header: {
            "Content-Type": "multipart/form-data"
          },
          formData:{
            'id':1
          },
          success: function (res) {
            that.setData({
              enterprise_logo: tempFilePaths,
            });

            // var data = JSON.parse(res.data);
            //服务器返回格式: { "Catalog": "testFolder", "FileName": "1.jpg", "Url": "https://test.com/1.jpg" }
            console.log(res);
          },
          fail: function (res) {
            wx.hideToast();
            wx.showModal({
              title: '错误提示',
              content: '上传图片失败',
              showCancel: false,
              success: function (res) { }
            })
          }
        });
        console.log(res);
      },
      fail: function(res) {},
      complete: function(res) {},
    })
  },
  chooseVideo: function (e) {
    var that = this;
    wx.chooseVideo({
      sourceType: ['album', 'camera'],
      compressed:true,
      maxDuration:60,
      success: function (res) {
        console.log(res)
        //启动上传等待中...
        wx.showToast({
          title: '正在上传...',
          icon: 'loading',
          mask: true,
          duration: 10000
        })

        wx.uploadFile({
          url: 'http://www.recruit.com/api/enterprise/uploadVideo',
          filePath: res.tempFilePath,
          name: 'file',
          header: {
            "Content-Type": "multipart/form-data"
          },
          formData: {
            'id': 1
          },
          success: function (res) {
            wx.showToast({
              title: '上传成功',
              icon: 'success',
              mask: true,
              duration: 2000
            })
          },
          fail: function (res) {
            wx.hideToast();
            wx.showModal({
              title: '错误提示',
              content: '上传视频失败',
              showCancel: false
            })
          }
        });
      },
      fail: function (res) { },
      complete: function (res) { },
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      //获取公司的初始数据
    var that = this;
    wx.request({
      url: 'http://www.recruit.com/api/industry/industry/sel',
      success:function(e){
        console.log(e.data.data);
        var arr = [];
          arr.push("请选择");
          for(var i=0;i<e.data.data.length;i++) {
            arr.push(e.data.data[i].industry_name);
          }
        that.setData({
          casArray:arr,        
        })
      }
    })
    wx.request({
      url: 'http://www.recruit.com/api/enterprise/selone',
      data: { id: 1 },
      success: function (e) {
        console.log(e)
        that.setData({
          enterprise_corporate_name: e.data.data.enterprise_corporate_name,
          enterprise_logo: e.data.data.enterprise_logo,
          enterprise_credit_code: e.data.data.enterprise_credit_code,
          enterprise_unit_address: e.data.data.enterprise_unit_address,
          enterprise_mailbox: e.data.data.enterprise_mailbox,
          enterprise_company_profile: e.data.data.enterprise_company_profile,
          enterprise_company_industry: e.data.data.enterprise_company_industry,
          enterprise_business_license: e.data.data.enterprise_business_license,
          
        })
      }
    })
  },
  /**
   * 上传数据
   */
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  formSubmit:function(e)
  {
    wx.showModal({
      title: '提交成功',
      content: '我们将在2个工作日完成审核，审核完成后会有短信通知，请注意查收',
      confirmText: '确定',
      success: function (res) {
        if (res.confirm) {
          wx.request({
            url: 'http://www.recruit.com/api/enterprise/save',
            header: {
              'content-type': 'application/x-www-form-urlencoded'
            },
            method: 'POST',
            data:{
              id:1,
              enterprise_company_profile: e.detail.value.enterprise_company_profile,
              enterprise_corporate_name: e.detail.value.enterprise_corporate_name,
              enterprise_credit_code: e.detail.value.enterprise_credit_code,
              enterprise_mailbox: e.detail.value.enterprise_mailbox,
              enterprise_unit_address: e.detail.value.enterprise_unit_address,
              enterprise_company_industry: e.detail.value.enterprise_company_industry,
              enterprise_business_license: e.detail.value.enterprise_business_license,
              enterprise_unit_size: e.detail.value.enterprise_unit_size,
              enterprise_industry: e.detail.value.enterprise_industry
            },
            success:function(a){
              console.log(a)
            }
          })
          console.log(e);
        } else {
          console.log('用户点击取消')
        }

      }
    })
    setTimeout(function () {

      wx.hideToast()

    }, 2000)
  }
})